<title>网站用户</title>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>用户</cite></a>
    <a><cite>网站用户</cite></a>
  </div>
</div>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <div style="padding-bottom: 10px;">
      </div>
      <table id="tableAdmin" lay-filter="tableAdmin"></table>
      <script type="text/html" id="barDemo">
        <div class="layui-btn-group">
          <button class="layui-btn layuiadmin-btn-useradmin" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加</button>
          <button class="layui-btn layuiadmin-btn-useradmin" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</button>
          <button class="layui-btn layuiadmin-btn-useradmin" lay-event="batchDel"><i class="layui-icon layui-icon-delete"></i>删除</button>
          <button class="layui-btn layuiadmin-btn-useradmin" lay-event="bindQR"><i class="layui-icon layui-icon-vercode"></i>绑定二维码</button>
        </div>
      </script>
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'table'], function(){
  let $ = layui.$;
  var admin = layui.admin;
  let view = layui.view;
  let table = layui.table;
  let form = layui.form;
  
  form.render(null, 'layadmin-userfront-formlist');
  
  //监听搜索
  form.on('submit(LAY-user-front-search)', function(data){
    var field = data.field;
    
    //执行重载
    table.reload('tableAdmin', {
      where: field
    });
  });

  table.render({
    elem: '#tableAdmin',
    toolbar: '#barDemo',
    url: layui.setter.baseUrl + "/JwtAPI/Admin/Admins",
    method: "get",
    headers: {
      Authorization: layui.data(layui.setter.tableName).Authorization
    },
    where: {},
    page: true,
    cols: [[ //表头
      {type: 'checkbox', fixed: 'left'},
      {field: 'id', title: 'ID', width:120, sort: true, fixed: 'center'},
      {field: 'orgGuid', title: '组织ID', width:150},
      {field: 'phone', title: '电话', width: 150},
      {field: 'name', title: '姓名', width:150},
      {field: 'weChatOpenId', title: '微信OpenId', width: 300},
      {field: 'unionID', title: '平台ID', width:150},
      {field: 'role', title: '角色'}
    ]],
    parseData: function(res){ //res 即为原始返回的数据
      return {
        "code": res.code, //解析接口状态
        "msg": res.msg, //解析提示文本
        "count": res.count, //解析数据长度
        "data": res.data //解析数据列表
      };
    },
    text: {
      none: '暂无相关数据'
    }
  });

  table.on('toolbar(tableAdmin)', function(obj){
    let checkStatus = table.checkStatus(obj.config.id);
    let data = checkStatus.data;
    switch(obj.event){
      case 'add':
        layer.alert(JSON.stringify(obj));
        break;
      case 'edit':
        layer.msg('选中了：');
        break;
      case 'bindQR':
        if (data.length !== 1) {
          layer.msg("请选择一行数据。");
          return false;
        }
        break;
      case 'batchDel':
        layer.alert('这是工具栏右侧自定义的一个图标按钮');
        break;
    }
  })
});
</script>